import datetime
from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.globals import ThemeType
 
def Gen(times, kbps, delay, fps, mfps):
    line = Line(init_opts=opts.InitOpts(width="100%",
                                height="750px",
                                page_title="QOS 监控",
                                theme=ThemeType.LIGHT))
    line.add_xaxis(times)

    line.add_yaxis('码率(kbps)', kbps, 
          stack="总量",
          is_smooth=True, 
          markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")])
          )

    line.add_yaxis('延时(ms)', delay, 
          stack="总量",
          is_smooth=True, 
          markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")])
          )

    line.add_yaxis('帧率', fps, 
          stack="总量",
          is_smooth=True, 
          markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min")])
          )
   

    line.add_yaxis('丢帧率', mfps, 
          stack="总量",
          is_smooth=True, 
          markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")])
         )
   

    line.set_global_opts(title_opts=opts.TitleOpts(title="推流QOS监控", subtitle="精度(秒)"),
        tooltip_opts=opts.TooltipOpts(trigger="axis"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=True),
    )
 
    line.render("/tmp/tmp.htm")
